<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>汽车</title>
    <script th:src="@{/js/jquery-1.4.2.js}"></script>
    <script th:src="@{/js/bootstrap.js}"></script>
    <link type="text/css" rel="stylesheet" th:href="@{/css/bootstrap.css}">
</head>
<body>
<h1>汽车</h1>
<label th:text="${msg}"></label>
<table class="table table-bordered">
    <thead>
    <tr>
        <td>主键(id)</td>
        <td>名称(name)</td>
        <td>价格(price)</td>
        <td>颜色(colour)</td>
        <td>品牌(brand)</td>
    </tr>
    </thead>
    <tbody>
    <tr th:each="car:${listPageInfo.list}">
        <td th:text="${car.id}"></td>
        <td th:text="${car.name}"></td>
        <td th:text="${car.price}"></td>
        <td th:text="${car.colour}"></td>
        <td th:text="${car.brand}"></td>
    </tr>
    </tbody>
</table>
<form action="/springboot/insertCarByExcel" enctype="multipart/form-data" method="post">
    <input type="file" name="file">
    <input class="btn btn-success" type="submit" value="导入"/>
</form>
<input class="btn btn-info" type="button" value="导出" onclick="exportExcel()"/>
<nav aria-label="Page navigation">
    <ul class="pagination">
        <li th:if="${listPageInfo.pageNum != listPageInfo.firstPage}">
            <a th:href="@{/carList(pageNum=1)}"
               aria-label="Previous">
                <span aria-hidden="true">首页</span>
            </a>
        </li>
        <li th:if="${listPageInfo.pageNum != listPageInfo.firstPage}">
            <a th:href="@{/carList(pageNum=${listPageInfo.pageNum - 1})}"
               aria-label="Previous">
                <span aria-hidden="true">上一页</span>
            </a>
        </li>

        <li th:if="${listPageInfo.pages <= 5}"><a th:each="index:${#numbers.sequence(1,listPageInfo.pages)}"
                                                  th:text="${index}"
                                                  th:href="@{/carList(pageNum=${index})}"></a></li>

        <li th:if="${listPageInfo.pages > 5}">
            <a th:if="${listPageInfo.pageNum <= 3}" th:each="index:${#numbers.sequence(1,5)}"
               th:text="${index}" th:href="@{/carList(pageNum=${index})}"></a>
            <a th:if="${listPageInfo.pageNum > 3}"
               th:each="index:${#numbers.sequence(listPageInfo.pageNum - 2,listPageInfo.pageNum + 2)}"
               th:text="${index}" th:href="@{/carList(pageNum=${index})}"></a>
        </li>

        <li th:if="${listPageInfo.pageNum != listPageInfo.lastPage}">
            <a aria-label="Next" th:href="@{/carList(pageNum=${listPageInfo.pageNum + 1})}">
                <span aria-hidden="true">下一页</span>
            </a>
        </li>
        <li th:if="${listPageInfo.pageNum != listPageInfo.lastPage}">
            <a aria-label="Next" th:href="@{/carList(pageNum=${listPageInfo.total})}">
                <span aria-hidden="true">尾页</span>
            </a>
        </li>
    </ul>
</nav>
<script>
    function exportExcel() {
        window.location.href = "/springboot/exportCarByExcel"
    }
</script>
</body>
</html>